package com.gx.smart.building.ui.modify.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.gx.smart.base.BaseViewModel;
import com.gx.smart.common.util.AppConfig;
import com.gx.smart.lib.http.api.AuthApiService;
import com.gx.smart.lib.http.api.asynctask.CallBack;
import com.gx.wisestone.uaa.grpc.lib.auth.UserModifyResp;


public class ModifyPasswordViewModel extends BaseViewModel {
    public MutableLiveData<Boolean> success = new MutableLiveData<>(false);

    public ModifyPasswordViewModel(@NonNull Application application) {
        super(application);
    }

    public void modify(String password) {
        String userId = SPUtils.getInstance().getString(AppConfig.USER_ID, "");
        String token = SPUtils.getInstance().getString(AppConfig.LOGIN_TOKEN, "");
        AuthApiService.getInstance().userModifyPassWord(password, userId, token, new CallBack<UserModifyResp>() {

            @Override
            public void callBack(UserModifyResp result) {
                if (result == null) {
                    error.setValue(true);
                    ToastUtils.showLong("服务器超时");
                    return;
                }

                if (result.getCode() == 100) {
                    ToastUtils.showLong("修改密码成功");
                    success.setValue(true);
                } else {
                    error.setValue(true);
                    ToastUtils.showLong(result.getMsg());
                }
            }
        });
    }
}
